#pragma once
#include "Common.h"
#include "ObjectPool.h"
#include "PageMap.h"

class PageCache
{
public:
	static PageCache* GetInstance() {
		return &_sInst;
	}
	Span* MapObjectToSpan(void* obj);
	Span* NewSpan(size_t k);
	Span* _NewSpan(size_t k);
	void ReleaseSpanToPageCache(Span* span);
	std::mutex _pageMtx;
private:
	SpanList _spanLists[NPAGES];
	ObjectPool<Span> _spanPool;
	// std::map<PAGE_ID, Span*> _idSpanMap;
	// std::unordered_map<PAGE_ID, Span*> _idSpanMap;
	TCMalloc_PageMap1<32 - PAGE_SHIFT> _idSpanMap;
	static PageCache _sInst;
private:
	PageCache(){}
	PageCache(const PageCache&) = delete;
};